﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS.Module
{
    public partial class ucTag : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["ID"]);
            cmsSanPhamDO objSanPham = new cmsSanPhamDO();
            objSanPham.SanPhamID = id;
            objSanPham = new cmsSanPhamBL().Select(objSanPham);
            if (!string.IsNullOrEmpty(objSanPham.TuKhoa))
            {
                TagDataBindding(objSanPham.TuKhoa);
            }
        }
        protected void TagDataBindding(string tag)
        {
            string TotalTag = "";
            TotalTag = tag;
            DataTable dt = new DataTable();
            dt.Columns.Add("TagItem");
            string tagItem = "";
            DataRow row;
            for (int i = 0; i < TotalTag.Length; i++)
            {
                if (TotalTag[i] != ',')
                {
                    tagItem += TotalTag[i];
                }
                else
                {
                    row = dt.NewRow();
                    row[0] = tagItem.Trim();
                    dt.Rows.Add(row);
                    tagItem = "";
                }
                if (tagItem.Length > 0)
                    if (i == TotalTag.Length - 1 && TotalTag[i] != ',')
                    {
                        row = dt.NewRow();
                        row[0] = tagItem.Trim();
                        dt.Rows.Add(row);
                        tagItem = "";
                    }
            }
            rptTag.DataSource = dt;
            rptTag.DataBind();
        }
        protected void rptTag_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //LinkButton btnTag = e.Item.FindControl("btnTag") as LinkButton;
            //if (btnTag != null)
            //    Response.Redirect("~/Tag.aspx?Keyword=" + btnTag.Text);
        }

        public string ChangeAV(string s)
        {
            return Ultility.Change_AV(s);
        }
    }
}